package nsfs

import "fmt"

type OpenFileMode uint8

func (m OpenFileMode) String() string {
	switch m {
	case OpenFileModeRead:
		return "Read"
	case OpenFileModeWrite:
		return "Write"
	case OpenFileModeAllowAppend:
		return "AllowAppend"
	case OpenFileModeReadWrite:
		return "ReadWrite"
	case OpenFileModeAll:
		return "All"
	default:
		return fmt.Sprintf("OpenFileMode(%d)", m)
	}
}

const (
	OpenFileModeRead        = OpenFileMode(1)
	OpenFileModeWrite       = OpenFileMode(2)
	OpenFileModeAllowAppend = OpenFileMode(4)
	OpenFileModeReadWrite   = OpenFileMode(OpenFileModeRead | OpenFileModeWrite)
	OpenFileModeAll         = OpenFileMode(OpenFileModeRead | OpenFileModeWrite | OpenFileModeAllowAppend)
)

func (m OpenFileMode) HasFlags(mode OpenFileMode) bool {
	return (mode & m) > 0
}
